package cn.com.huzo.repository.tech.impl;

import cn.com.huzo.model.entities.tech.CostForecastLinesEntity;
import cn.com.huzo.repository.tech.CostForecastLinesRepository;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 产品成本预测明细数据访问数据访问对象。
 *
 * @author 范学春
 */
@Repository("CostForecastLinesRepository")
public class CostForecastLinesRepositoryImpl extends GenericRepositoryImpl<CostForecastLinesEntity, String>
        implements CostForecastLinesRepository {

    private final String namespace = "cn.com.huzo.repository.tech.CostForecastLinesRepository";

    /**
     * 构造函数,设置the entity to ProductionSheetLinesRepositoryImpl.class.
     */
    public CostForecastLinesRepositoryImpl() {
        super(CostForecastLinesEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<CostForecastLinesEntity> fetchByHeaderKey(Long headerKey) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchAllByHeaderId"), headerKey);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertLinesByBom(Long headerId, Long bomHeaderId, Integer perColourQuantity) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("BomHeaderId", bomHeaderId);
        criterion.put("PerColourQuantity", perColourQuantity);
        
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertLinesByBom"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertLinesByNewMaterial(List<CostForecastLinesEntity> itemList) {
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertLinesByNewMaterial"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<CostForecastLinesEntity> itemsList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemsList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLinesByMaterialId(String linesId, Long materialId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("LinesId", linesId);
        criterion.put("MaterialId", materialId);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLinesByMaterialId"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(String key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchDelete(List<CostForecastLinesEntity> itemList) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchDelete"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer importLinesFromOtherCostForecast(Long headerId, Long importedHeaderId, Long createdBy, Long updatedBy) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("ImportedHeaderId", importedHeaderId);
        criterion.put("CreatedBy", createdBy);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertLinesFromOtherCostForecast"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertFromClipboard(Long headerId, String copiedLinesId, Long materialId,
            Long uomId, String specification, Integer orderNo, Long createdBy, Long updatedBy) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("CopiedLinesId", copiedLinesId);
        criterion.put("MaterialId", materialId);
        criterion.put("UomId", uomId);
        criterion.put("Specification", specification);
        criterion.put("OrderNo", orderNo);
        criterion.put("CreatedBy", createdBy);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertFromClipboard"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer resetLinesOrder(Long headerId) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "resetLinesOrder"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLinesOrder(List<CostForecastLinesEntity> itemsList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLinesOrder"), itemsList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer setDefaultUnitCost3(List<CostForecastLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "setDefaultUnitCost3"), itemList);
    }
}
